import java.util.Vector;
// Future Event Set

public class FES {

  /* FES: Future Event Set, sorted list of events */
  protected Vector events;
  
  /**
   * Constructs an empty FES
   */
  
  public FES() {
    events = new Vector();
  }
  
  /**
   * Adds an event to FES
   * @param newEvent the new event
   */
   
  public void addEvent(Event newEvent) {
    int insertIndex = 0;
    while (insertIndex < events.size()) {
      Event e = (Event) events.elementAt(insertIndex);
      if (e.getTime() > newEvent.getTime()) break;
      insertIndex++;
    }
    events.insertElementAt(newEvent, insertIndex);
  }

  /**
   * Returns and removes the first event from FES
   * @return the event that is removed from FES
   */
   
  public Event nextEvent() {
    Event firstEvent = (Event) events.elementAt(0);
    events.removeElementAt(0);
    return firstEvent;
  }

} 
